home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / sys / amiga / programmer / 638 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  4.4 KB

  1. Path: mail2news.demon.co.uk!sisyphus.demon.co.uk
  2. From: Dave.Sparks@sisyphus.demon.co.uk
  3. Newsgroups: comp.sys.amiga.programmer
  4. Subject: Re: PPC compilers
  5. Date: Tue, 9 Jan 96 22:57:34 +0000 (GMT)
  6. Organization: to be supplied
  7. Message-ID: <19960109.55D920.1497F@sisyphus.demon.co.uk>
  8. References: <john.hendrikx.40ka@grafix.xs4all.nl> <4ck47h$g07@maureen.teleport.com> <19960106.4EE928.CF59@sisyphus.demon.co.uk> <4cokkg$415@maureen.teleport.com> <19960107.533250.14585@sisyphus.demon.co.uk> <4cqrti$f6u@maureen.teleport.com>
  9. X-NNTP-Posting-Host: sisyphus.demon.co.uk
  10. In-reply-to: sschaem@teleport.com's message of 8 Jan 1996 10:33:22 GMT
  11. X-Attribution: DaveS
  12. Content-Length: 3768
  13. X-Lines: 99
  14. X-Mail2News-Path: relay-4.mail.demon.net!post.demon.co.uk!sisyphus.demon.co.uk
  15.  
  16. >>>>> "SS" == Stephan Schaem <sschaem@teleport.com> writes:
  17.  
  18.   SS> Dave.Sparks@sisyphus.demon.co.uk wrote:
  19.  
  20.   SS> I cant see how people can write code without knowing what data
  21.   SS> or type they manipulate...
  22.  
  23.   >> Real-world programmers do it all the time.  If you ever want to
  24.  
  25.   SS> So you do math operation without knowing that your destination need
  26.   SS> to be a float or a 2 byte int?
  27.  
  28.   >> Yes.  This is a trivial example of polymorphism.
  29.  
  30.   SS>  polymorphism?
  31.  
  32.   SS>  int a,b,c;
  33.  
  34.   SS>  ...  a = b /c; a *= result; ...  struct.float = a;
  35.  
  36.   SS>  I dunno , I just find it puzzling to declar variable without giving
  37.   SS> a care of what its usage will be. You programing practice is VERY
  38.   SS> unwise...
  39.  
  40. If I want to store a value of type clock_t, I declare a value of
  41. type clock_t - knowing that it could be signed or unsigned int or
  42. long, or float or double.
  43.  
  44.  I guess I really have to spoon feed you a real life example.
  45.  
  46.     clock_t start_time, end_time;
  47.     double time_used;
  48.     ...
  49.     start_time = clock ();
  50.     ...
  51.     end_time = clock ();
  52.     time_used = ((double) (end_time - start_time)) / CLOCKS_PER_SEC;
  53.     ...
  54.     printf ("Time used was %.3f seconds/n", time_used);
  55.  
  56. is hardware-independent ANSI C.  Don't worry about the few
  57. floating-point operations: anyone who is worried about performance
  58. will have hardware which can execute floating-point ops
  59. asynchronously.  If the C compiler does its job properly and
  60. generates the instructions in the best order, the floating-point
  61. ops will be executed in parallel and the total execution time may
  62. even be _less_ than the time which would have been needed if
  63. fixed-point had been used.
  64.  
  65.   SS>  You said yourself after peeking at the .h that clock_t was
  66.   SS>  a ulong.
  67.  
  68. I didn't peek the .h , I read the docs.  And my code doesn't
  69. depend on clock_t being unsigned long.
  70.  
  71.   SS> ...
  72.  
  73.   SS> about loop counter size... should I use ulong and forget about it, or
  74.   SS> use ushort to be sure of optimal speed on my target CPU and remember
  75.   SS> my declaration type in case I want to use it for a loop count bigger
  76.   SS> then 65535?. (this result in a sub/bcc vs dbcc encoding on 680x0... )
  77.  
  78.   >> target CPU?  How quaint ...
  79.  
  80.   SS>  But target CPU is something that come up often in the real world of
  81.   SS> programming... oh, forgot you think you are part of it.  C compiler
  82.  
  83. If your product is a large, expensive program with a small niche
  84. market, and your various potential customers use Amiga, SUN,
  85. RS6000 or HP, you can't afford to target your code on a single
  86. processor type.  You may have to write some parts of your program
  87. in assembly code, either for performance or because some functions
  88. can't be performed in C, but you'll be reluctant to do so because
  89. the assembly code will have to be written and tested four times.
  90.  
  91.   SS> ...
  92.  
  93.   >> ...
  94.   >> loop; it couldn't use dbcc anyway.  You don't get optimal speed by
  95.   >> optimizing the instructions, but by optimizing the algorithm.
  96.  
  97.   SS> ...
  98.  
  99.   SS>  The way you get optimal speed is optimizing the optimal algorithim.
  100.   SS> If you stop at the algorithm you loose... Optimizing at this stage
  101.   SS> will give an exponential result on the work you done on the
  102.   SS> algorithm.  And usually this stage is done in assembler.
  103.  
  104. Getting the algorithm right can improve performance by orders of
  105. magnitude (i.e. not thinking about the algorithm can degrade
  106. performance by a factor of ten or more).  Writing everything in
  107. assembler might save 20% over writing everything in C and using a
  108. good compiler.  Writing the bulk of your code in C and a small
  109. proportion (less than 5%) in assembler is usually a good compromise.
  110.  
  111. -- 
  112.         Dave.Sparks@sisyphus.demon.co.uk        (Staffordshire, England)
  113.  
  114.  ... details are more implementation-dependant than defined.
  115.  
  116.  
  117.